package com.mantru.iotpot.Receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.PowerManager;
import android.provider.Settings;
import android.net.Uri;

import com.mantru.iotpot.Begin.FirstActivity;

public class BootReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
            if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
                // 启动SerialTestActivity
                Intent launchIntent = new Intent(context, FirstActivity.class);
//            Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage("com.hzmct.serialport");
                launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(launchIntent);
            }
        }

//    /**
//     * 请求忽略电池优化
//     */
//    private void requestIgnoreBatteryOptimizations(Context context) {
//        String packageName = context.getPackageName();
//        PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
//
//        // 检查是否已经忽略电池优化
//        if (!pm.isIgnoringBatteryOptimizations(packageName)) {
//            Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
//            intent.setData(Uri.parse("package:" + packageName));
//            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//            context.startActivity(intent);
//        }
//    }
    }
}